#ifndef CAMERA_H
#define CAMERA_H

#include <QWidget>
#include <QCamera>
#include <QMediaRecorder>

QT_BEGIN_NAMESPACE
namespace Ui { class Camera; }
QT_END_NAMESPACE

class QCameraImageCapture;
class QLabel;

class Camera : public QWidget
{
    Q_OBJECT

public:
    Camera(QWidget *parent = nullptr);
    ~Camera();

private slots:
    //QCamera的槽函数
    void onCameraStateChanged (QCamera::State state) ;
    void onCameraCaptureModeChanged (QCamera::CaptureModes mode);

    //QCameraImageCapture的槽函数
    void onImageReadyForCapture (bool ready);
    void onImageCaptured(int id, const QImage &preview);
    void onImageSaved(int id, const QString &fileName);

    // QMediaRecorder 的槽函数
    void onVideoStateChanged (QMediaRecorder::State state) ;
    void onVideoDurationChanged(qint64 duration) ;

    //ui 设计器自动关联槽函数
    void on_actStartCamera_clicked();
    void on_actStopCamera_clicked();
    void on_actCapture_clicked();
    void on_actVideoRecord_clicked();
    void on_actVideoStop_clicked();

private:

    void  iniCamera();//初始化
    void  iniImageCapture() ; //初始化静态抓图
    void  iniVideoRecorder() ; //初始化视频录制
private:
    Ui::Camera *ui;

    QCamera * curCamera=Q_NULLPTR;
    QCameraImageCapture * imageCapture = Q_NULLPTR; //抓图
    QMediaRecorder *mediaRecorder = Q_NULLPTR; //录像

};
#endif // CAMERA_H
